/**Trigger Name: NMRAccountShareTrg
 * Author: Accenture
 * Requirement/Project Name: NMR
 * Requirement Description: Account should be shared with Secondary Account Owner
 */
trigger NMRAccountShareTrg on Account (after insert,after update) {
    Id nmrAccountRT = RecordTypeHelper.GetRecordTypeID('Account', 'CSS Customer');
    Map<Id,Id> ownerIdMap = new Map<Id,Id>();
    Map<Id,Id> ownerIdMapDelete = new Map<Id,Id>();
    for(Account acc:Trigger.new){
      if(acc.recordtypeId==nmrAccountRT){
        if(Trigger.ISINSERT || (Trigger.oldmap.get(acc.Id).OOR_Secondary_Account_Owner__c != acc.OOR_Secondary_Account_Owner__c)){
            if(acc.OOR_Secondary_Account_Owner__c != NULL){
                
                ownerIdMap.put(acc.Id,acc.OOR_Secondary_Account_Owner__c);
            }
            if(Trigger.ISUPDATE){
                if(Trigger.oldmap.get(acc.Id).OOR_Secondary_Account_Owner__c != NULL){
                    ownerIdMapDelete.put(acc.Id,Trigger.oldmap.get(acc.Id).OOR_Secondary_Account_Owner__c);
                }
            }
        }
      }
    }
    if(ownerIdMap.size()>0 || ownerIdMapDelete.size()>0 ){
    
         NMRCreateAccOpptyShare.createShare(ownerIdMap,ownerIdMapDelete);
    }
}